<template>
    <h1>注册页面</h1>

    <table>
        <tr>
            <td>用户名</td>
            <td>
                <input type="text" v-model="User.T_UName" />
            </td>
        </tr>
        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="User.T_Pwd" />
            </td>
        </tr>

        <tr>
            <td>年收益</td>
            <td>
                <input type="text" v-model="User.T_Money" />
            </td>
        </tr>

        <tr>
            <td>性别</td>
            <td>
                <input type="radio" name="sex" value="男" v-model="User.T_Sex" />男
                <input type="radio" name="sex" value="女" v-model="User.T_Sex" />女
            </td>
        </tr>

        <tr>
            <td>身份证号</td>
            <td>
                <input type="text" v-model="User.T_Card" >
            </td>
        </tr>

        <tr>
            <td>地址</td>
            <td>
                <input type="text" v-model="User.T_Addres" />
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="注册" @click="Login" />
            </td>
        </tr>

    </table>

</template>

<script setup lang="ts">
import {ref} from 'vue'
import axios from 'axios'
import {useRouter} from 'vue-router'

const router = useRouter()

const User = ref({
    T_UName:'',
    T_Pwd:'',
    T_Money:'',
    T_Sex:'',
    T_Card:'',
    T_Addres:'',
})

const Login = ()=>{
    axios({
        method:'post',
        url:'http://localhost:61590/api/User/AddUser',
        data:{
            T_UName:User.value.T_UName,
            T_Pwd:User.value.T_Pwd,
            T_Money:User.value.T_Money,
            T_Sex:User.value.T_Sex,
            T_Card:User.value.T_Card,
            T_Addres:User.value.T_Addres,
        }
    })
    .then(function (res){
        if(res.data>0){
            alert("注册成功");
            router.push('/UserLogin');
        }
        else if(res.data==-1){
            alert("用户名已存在");
            return;
        }
        else{
            alert("注册失败");
            return;
        }
    })
    .catch(function (error){
        console.log(error);
    })
}

</script>
